(function($, owner) {

	owner.login = function(loginInfo, callback) {
		callback = callback || $.noop;
		loginInfo = loginInfo || {};
		loginInfo.account = loginInfo.account || '';
		loginInfo.password = loginInfo.password || '';
		if(loginInfo.account==''){
			return callback('请输入账号');
		}
		/* if (loginInfo.account.length < 5) {
			return callback('账号最短为 5 个字符');
		} */
		if(loginInfo.password==''){
			return callback('请输入密码');
		}
		if (loginInfo.password.length < 3) {
			return callback('密码最短为 3 个字符');
		}

		var phoneUuid = plus.device.uuid;
		var versionName = plus.runtime.version;
		var versionCode = plus.runtime.versionCode
		var model = plus.device.model;
		var osversion = plus.os.version;

		// url地址
		var url = BASE_URL + 'cc/login/login';
		// 参数
		var params = {
			"email": loginInfo.account,
			"password": loginInfo.password,
			"phoneUuid": phoneUuid,
			"registrationId": RegistrationID,
			"versionName": versionName,
			"versionCode": versionCode,
			"model": model,
			"osversion": osversion
		}

		ajaxPost(url, params, function(data) {
			if (data.code === 200) {
				app.createState(data.data, callback);
			} else if (data.code === 204){
				callback(data.msg);
			} else {
				callback(data.msg);
			}
		}, function(err) {
			console.log(err)
			callback(err);
		})




		// var user = [{
		// 	"account": "xiaoguo",
		// 	"password": "123456"
		// }]
		// h.setItem('$users', JSON.stringify(user));

		// var users = JSON.parse(h.getItem('$users') || '[]');
		// var authed = users.some(function(user) {
		// 	return loginInfo.account == user.account && loginInfo.password == user.password;
		// });
		// if (authed) {
		// 	return app.createState(loginInfo.account, callback);
		// } else {
		// 	return callback('用户名或密码错误');
		// }
	}
}(mui, window.login = {}))